package me.shurufa.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.model.Message;
import me.shurufa.utils.Utils;
import me.shurufa.widget.CircleImageView;

/**
 * 消息外部列表ViewHolder
 *
 * @FileName: me.shurufa.holder.MessageViewHolder.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-26 16:29
 */
public class MessageViewHolder extends BaseViewHolder{

    @Bind(R.id.avatar)
    CircleImageView avatar;
    @Bind(R.id.date)
    TextView date;
    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.notice_point)
    ImageView noticePoint;
    @Bind(R.id.text)
    TextView text;
    @Bind(R.id.msg_view)
    RelativeLayout msgView;

    private Context mContext;
    private Message mMessage;

    public MessageViewHolder(View itemView, Object parent) {
        super(itemView, parent);
        mContext = itemView.getContext();
        ButterKnife.bind(this, itemView);
        addOnClickListener(msgView);
    }

    public void bind(Message message) {
        if (message == null)
            return;
        mMessage = message;
        if (!TextUtils.isEmpty(message.user_info.avatar))
            Glide.with(mContext).load(message.user_info.avatar).into(avatar);
        else
            avatar.setImageResource(R.drawable.default_avatar);
        if (!TextUtils.isEmpty(message.user_info.username))
            name.setText(message.user_info.username);
        if (!TextUtils.isEmpty(message.message))
            text.setText(message.message);
        if (message.dateline!=0L)
            date.setText(Utils.getDatetimeStr(message.dateline*1000L));
        if (message.isnew==0)
            noticePoint.setVisibility(View.INVISIBLE);
        else noticePoint.setVisibility(View.VISIBLE);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.msg_view:
                //TODO 跳转至聊天界面
                Utils.showToast(mMessage.message);
                break;
        }
    }
}
